clear; clc;

%% Generate the Baseline Results
FileName    =   'Result_Baseline';
StdVec      =   [1 1 1 -1 -1 60 -10]'*0.01/4;
PP          =   Setup_PP(struct('KAPPA',0.00/4,'XI',1/82.5/4,'Pir_SS',0.02/4,...
                                'Flag_dE',0,'Flag_Price',0,...
                                'B_Total_SS',0.91,'b_lb',-0.29,...
                                'TrProb_H',0.98,'Prob_H',0.37,...
                                'TrProb_ext',0.92,'Prob_ext',0.33,...
                                'Fin_DomShare',0.79,'Fin_AdjCost',0.8,...
                                'Cons_FracH',0.60,...
                                'RHO_M_dom',0.68,'RHO_M_ext',0.81,'RHO_Y_H',0.5,'RHO_p_F',0.90,...
                                'Taylor_Pi',1.1,'Taylor_ir',0.87,...
                                'Cons_ElasTN',6.19,'Cons_ElasHF',6.19));
Solver_Main(PP,StdVec,'FileName',FileName);
%% Different Results
load([FileName,'.mat']);
IRF             =   TempFun_AugIRF(PP,SS,MODEL,EquJac,IRF);

% Baseline
[IRF_Main,SOLUTION_Main] ...
                =   TempFun_NewIRF(PP,SS,MODEL,EquJac,StdVec);

% Fixed Exchange Rate
TempPP          =   PP;
TempPP.Taylor_dE=   10;

[IRF_ER_Fixed,SOLUTION_ER_Fixed] ...
                =   TempFun_NewIRF(TempPP,SS,MODEL,EquJac,StdVec);

% Dollar Pricing System
TempPP          =   PP;
TempPP.Flag_Price=  1;

[IRF_Pricing_Int,SOLUTION_Pricing_Int] ...
                =   TempFun_NewIRF(TempPP,SS,MODEL,EquJac,StdVec);

% No UIP Deviation
TempPP          =   PP;
TempPP.Fin_AdjCost= 0.0001;

[IRF_NoDevUIP,SOLUTION_NoDevUIP] ...
                =   TempFun_NewIRF(TempPP,SS,MODEL,EquJac,StdVec);


save('IRF.mat','IRF_Main','IRF_ER_Fixed','IRF_Pricing_Int','IRF_NoDevUIP');
save('SOLUTION.mat','SOLUTION_Main','SOLUTION_ER_Fixed','SOLUTION_Pricing_Int','SOLUTION_NoDevUIP');

%% Figures
Figure_Unit('TableGraphs//Main//',SS,IRF_Main);
Figure_Unit('TableGraphs//ER_Fixed//',SS,IRF_ER_Fixed);
Figure_Unit('TableGraphs//Pricing_DCP//',SS,IRF_Pricing_Int);
Figure_Pair('TableGraphs//ER_Flexible_vs_Fixed//',SS,{IRF_Main,IRF_ER_Fixed},{'Flexible Exchange Rate','Fixed Exchange Rate'});
Figure_Pair('TableGraphs//Pricing_PCP_vs_DCP//',SS,{IRF_Main,IRF_Pricing_Int},{'Producer Currency Pricing','Dollar Currency Pricing'});
Figure_Unit('TableGraphs//NoDevUIP//',SS,IRF_NoDevUIP);
%% Decomposition
Step_2_Decomposition(SOLUTION_Main,['TableGraphs//Main//Decomposition//']);
Step_2_Decomposition(SOLUTION_ER_Fixed,['TableGraphs//ER_Fixed//Decomposition//']);